/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package wallythewatermelon;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 *
 * @author matthewweidman
 */
public class KeyDetector implements KeyListener {
    public static boolean goingLeft = false, goingRight = false;
    
    @Override
    public void keyTyped(KeyEvent e) {
        e.consume();
    }

    @Override
    public void keyPressed(KeyEvent e) {
        if (DrawManager.getDrawIndex() == DrawManager.LEVELS) {
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                KeyDetector.goingRight = true;
                DrawManager.getWally().img=DrawManager.wallyMovingRight;
            } if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                DrawManager.getWally().img=DrawManager.wallyMovingLeft;
                KeyDetector.goingLeft = true;
            } if (e.getKeyCode() == KeyEvent.VK_UP) {
                if (DrawManager.getWally().standingOnBlock()) {
                    DrawManager.getWally().jump();
                }
            }
        }
        e.consume();
    }

    @Override
    public void keyReleased(KeyEvent e) {
        if (DrawManager.getDrawIndex() == DrawManager.LEVELS) {
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                KeyDetector.goingRight = false;
            } if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                KeyDetector.goingLeft = false;
            }
        }
        e.consume();
    }
    
}
